package top.someapp.dxf2dsvg.dxf;

import top.someapp.dxf2dsvg.entity.Entities;
import top.someapp.dxf2dsvg.entity.Entity;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

/**
 * @author zwz
 * Created on 2020-04-17
 */
public class SectionEntities implements Section {
    private List<Entity> entityList = new ArrayList<>(); // 图元
    Entity entity;

    @Override
    public SectionName name() {
        return SectionName.ENTITIES;
    }

    @Override
    public List<Item> items() {
        return null;
    }

    @Override
    public void onItemFound(@Nonnull Item item) {
//        System.out.println("item in entities: " + item);
        if (item.code < 0) return;
        if (item.code == 0) { // a new entity start
            entity = Entities.make(item.value);
            entityList.add(entity);
        } else {
//            System.out.println(entity.type() + " setup with: " + item);
            entity.setup(item);
        }
    }

    public List<Entity> getEntityList() {
        return entityList;
    }

    @Override
    public String toString() {
        return "SectionEntities{" +
                "entityList=" + entityList +
                '}';
    }
}
